
const objectUtils = {
  isNotEmpty: function (arg) {
    if (arg instanceof Array) {
      for (var i = 0; i < arg.length; i++) {
        if (arg[i] == null || arg[i] === '') {
          return false
        }
      }
      return true
    } else {
      if (arg != null && arg !== '') {
        return true
      }
      return false
    }
  },
  isEmpty: function (arg) {
    if (arg == null || arg === '') {
      return true
    }
    return false
  },
  inArray: function(array, item) {
    let result = -1
    let aitem = null
    if (array.length === 0) {
      return result
    }
    for (let i = 0; i < array.length; i++) {
      aitem = array[i]
      if (aitem === item) {
        result = 1
        break
      }
    }
    return result === 1
  },
  checkPhone: function (phone) {
    var reg = /^0?1[3|4|5|7|8|9][0-9]\d{8}$/
    return reg.test(phone)
  },
  checkPassword: function(str) {
    if (/^\d+$/.test(str) || /^[a-zA-Z]+$/.test(str) || /^[\W_]+$/.test(str)) {
      return false
    }
    if (str.length < 8) {
      return false
    }
    return true
  },
  turnTodate: function (timestamp) { // 转化为yyyy-MM-dd HH:mm
    var date = new Date(timestamp)
    var year = date.getFullYear()
    var month = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
    var day = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())
    var hour = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours())
    var minute = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes())
    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute
  },

  turnNowDate: function (timestamp) { // 转化为yyyy-MM-dd
    var date = new Date(timestamp)
    var year = date.getFullYear()
    var month = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
    var day = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())
    return year + '-' + month + '-' + day
  },
  GetRequest: function() {
    let url = location.search
    let theRequest = {}
    if (url.indexOf('?') !== -1) {
      let str = url.substr(1)
      let strs = str.split('&')
      for (var i = 0; i < strs.length; i++) {
        theRequest[strs[i].split('=')[0]] = (strs[i].split('=')[1])
      }
    }
    return theRequest
  }
}

export default objectUtils
